package com.niji.littly_donkey_android.adapter;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.makeramen.roundedimageview.RoundedImageView;
import com.niji.littly_donkey_android.R;
import com.niji.littly_donkey_android.bean.Photo;
import com.niji.littly_donkey_android.bean.Video;
import com.niji.littly_donkey_android.util.BitMapUtil;
import com.niji.littly_donkey_android.util.CirclePhotoUtil;
import com.niji.littly_donkey_android.util.NetworkGlideImageLoader;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class CommentPhotosAdapter extends RecyclerView.Adapter<CommentPhotosAdapter.ViewHolder> {


    private static final String TAG = "CommentPhotosAdapter";

    private List<Photo> photos;

    private Context mContext;

    private List<Photo> mData;//网络图片路径集合
    public CommentPhotosAdapter(Context context,List<Photo> photos){
        this.mContext = context;
        this.photos = photos;
        setImages(photos);

    }

    private void setImages(List<Photo> photos) {
        mData = new ArrayList<>(photos);
        notifyDataSetChanged();
    }


    @NonNull
    @NotNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_comment_photos,parent,false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull CommentPhotosAdapter.ViewHolder holder, int position) {
        RoundedImageView comment_img = holder.comment_img;
        Photo photo = photos.get(position);

        //用Glide加载网络图片
        NetworkGlideImageLoader.getInstance().displayImage((Activity) mContext,photo.getUrl(),comment_img,0,0);
    }

    @Override
    public int getItemCount() {
        return photos.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        RoundedImageView comment_img;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            comment_img = itemView.findViewById(R.id.comment_img);
        }
    }

}



